#define LG_CORE

#include "lg_canvas.h"
#include "lg_window.h"

static struct {
	LGConfig* config;
	LGCanvasBackend* backend;
}gCtx = { 0 };


static void
freeCanvas(void* ref) {
	LGCanvas* canvas = (LGCanvas*)ref;
	gCtx.backend->freeCanvas(canvas);
}

LG_API int
lgInitCanvasContext(LGConfig* config, LGCanvasBackend* backend) {
	gCtx.config = config;
	gCtx.backend = backend;
	return 0;
}

LG_API LGCanvas*
lgNewCanvas(unsigned width, unsigned height) {
	size_t size = gCtx.backend->sizeofCanvas();
	LGCanvas* canvas = lgNewRef(size, freeCanvas);
	canvas->width = width;
	canvas->height = height;
	lgIdentityMatrix(&canvas->projection);
	lgIdentityMatrix(&canvas->view);
	gCtx.backend->newCanvas(canvas);
	return canvas;
}

LG_API void
lgResizeCanvas(LGCanvas* canvas, unsigned width, unsigned height) {
	canvas->width = width;
	canvas->height = height;
}

LG_API void
lgSetCanvasColor(LGCanvas* canvas, LGVector* color) {
	canvas->color = *color;
}

LG_API void
lgClearCanvas(LGCanvas* canvas) {
	gCtx.backend->clearCanvas(canvas);
}

LG_API void
lgSetCanvasProjection(LGCanvas* canvas, LGMatrix* proj) {
	canvas->projection = *proj;
}

LG_API void
lgSetCanvasView(LGCanvas* canvas, LGMatrix* view) {
	canvas->view = *view;
}

